<?php
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Utils\HD;
use Illuminate\Support\Facades\Redis;

class IndexController extends Controller
{
    public function index()
    {
        die(dump(111));
    }


    public function test()
    {
        Redis::set('test',1);
        dd(Redis::get('test'));
        //生成数字货币钱包地址
        /*$uid = 1;
        $xpub = 'xpub6E6c6mAXMMM8i1VW9ZHk5Ri2KjCxotwFS3191RWzhq6XmkezNg9GAupERehcxxewvUcMXiS9tVgVGHreyCnpNRKQsTGaaEbW3GnWwKsEihZ';
//        $path = 1000000000 .'/'. 100000000 . '/' . 100000000;//大于等于0 && 小于等于 (2^31)-1
        $path = $uid;
        $hd = new HD();
        $hd->set_xpub($xpub);
        $address = $hd->address_from_master_pub($path);
        echo $address;*/

        $number = 100;
        if(!preg_match("/^[1-9][0-9]*$/" ,$number)){
            echo '请输入大于0的整数';
        }else{
            //判断是否100整数倍
            if($number%100 == 0){
                //手续费计算
                $service_rate = 2.5;
                //收取手续费
                $service_charge  = bcdiv(bcmul($number,$service_rate),100,2);
//            $service_charge = $number * $service_rate / 100;
                //实际转赠
                $real_number = bcsub($number,$service_charge,2);
//            $real_number = $number - $service_charge;
                echo $real_number;
            }else{
                echo '不是100的整数';
            }
        }
    }
}
